<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <meta charset="utf-8">
    <title>日志管理</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css" media="all">
</head>
<body style="margin-top: 80px;">
<form class="layui-form">
    <div class="layui-item" style="padding-left: 150px;height: 40px">
        <label class="layui-form-label">日期范围</label>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="start" id="start" placeholder="选择时间">
            </div>
        </div>
        <div class="layui-inline">-</div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="end" id="end" placeholder="选择时间">
            </div>
        </div>
        <div class="layui-inline">
            <button class="layui-btn" lay-filter="search" lay-submit>搜索</button>
        </div>
        <div class="layui-inline">
            <button class="layui-btn" lay-filter="reset" lay-submit>重置</button>
        </div>
        <div class="layui-inline">
            <button class="layui-btn" lay-filter="delete" lay-submit>删除日志(删除指定时间)</button>
        </div>
        <div class="layui-inline">
            <button class="layui-btn" lay-filter="empty" lay-submit>清空日志</button>
        </div>
    </div>
</form>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script src="${pageContext.request.contextPath}/static/layui/layui.js" charset="utf-8"></script>
<script>
    layui.use(['laydate','table','jquery','form'], function(){
        var laydate = layui.laydate;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.$;

        var start = laydate.render({
            elem: '#start'
            ,done: function(value, date, endDate){
                end.config.min = date;
                end.config.min.month = date.month -1;
            }
        });
        var end = laydate.render({
            elem: '#end'
            ,done: function(value, date, endDate){
                start.config.max = date;
                start.config.max.month = date.month -1;
            }
        });

        form.on('submit(search)', function (data) {
            data.field.start= $("#start").val();
            data.field.end= $("#end").val();
            console.log(data.field)
            //重新加载表格
            table.reload("test", {
                where: { //查询条件
                    params:data.field  //会封装到LayRequest中的params中
                },
                page: {
                    curr: 1
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        form.on('submit(reset)', function (data) {
            start.elem[start]="";
            end.elem[end]="";
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        form.on('submit(delete)', function (data) {
            var datetime = $("#end").val();
            data.field = datetime;
            console.log(data.field)
            $.post("${pageContext.request.contextPath}/zhou/delete?end="+datetime+"",data.field,function (result) {
                if (result.code==0){
                    layer.msg("删除日志成功");
                    //刷新父窗口的表格
                    parent.layui.table.reload("test",{
                        page:{
                            curr:1
                        }
                    });
                }
            },"json");
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        form.on('submit(empty)', function (data) {
            $.post("${pageContext.request.contextPath}/zhou/delete2",data.field,function (result) {
                if (result.code==0){
                    layer.msg("清空日志成功");
                    //刷新父窗口的表格
                    parent.layui.table.reload("test",{
                        page:{
                            curr:1
                        }
                    });
                }
            },"json");
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        table.render({
            elem: '#test'
            , url: '${pageContext.request.contextPath}/logs/list'
            , title: '角色数据表'
            , cols: [[
                {field: 'id', title: '日志ID', width: 180, edit: 'text'}
                , {field: 'operation_time', title: '操作时间', width: 180, edit: 'text'}
                , {field: 'operation_content', title: '操作内容', width: 820, edit: 'text'}
            ]]
            , page: true
        });
    });
</script>
</body>
</html>
